Conditions | 5 |
Paths | 12 |
Total Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict' |
||
16 | module.exports = function (slug) { |
||
17 | var template = 'basic' |
||
18 | |||
19 | // Get slug |
||
20 | var userName = (util.getSystemUsername() || 'user').toLowerCase() |
||
21 | if (slug.match(/^[a-z0-9-]+\/[a-z0-9-]+$/)) { |
||
22 | userName = slug.split('/')[0] |
||
23 | slug = slug.split('/')[1] |
||
24 | } |
||
25 | if (!slug.match(/^[a-z0-9-]+$/)) { |
||
26 | output.err('Module name should only contain lowercase letters, numbers and dashes.') |
||
27 | return |
||
28 | } |
||
29 | |||
30 | // Check if directory doesn't already exist |
||
31 | var stopSpinner = output.wait('Downloading template \'' + template + '\'') |
||
32 | if (fs.existsSync(slug)) { |
||
33 | stopSpinner('Directory \'' + slug + '\' already exists!') |
||
34 | return |
||
35 | } |
||
36 | |||
37 | try { |
||
38 | Kit.download(template, slug, function (err) { |
||
39 | if (err) { |
||
40 | stopSpinner(err) |
||
41 | return |
||
42 | } |
||
43 | stopSpinner(true) |
||
44 | |||
45 | // Write module.json |
||
46 | var json = util.moduleJSON(slug, userName, name({ |
||
47 | type: 'global' |
||
48 | }), email({ |
||
49 | type: 'global' |
||
50 | }), jsonfile.readFileSync(path.join(slug, 'module.json'))) |
||
51 | fs.writeFileSync(path.join(slug, 'module.json'), JSON.stringify(json, null, 3), 'utf8') |
||
52 | fs.writeFileSync(path.join(slug, 'composer.json'), JSON.stringify({ |
||
53 | 'require': {} |
||
54 | }, null, 3), 'utf8') |
||
55 | |||
56 | // Remove stock files |
||
57 | try { fs.unlinkSync(path.join(slug, 'LICENSE.md')) } catch (e) {} |
||
58 | try { fs.unlinkSync(path.join(slug, 'LICENSE')) } catch (e) {} |
||
59 | try { fs.unlinkSync(path.join(slug, 'README')) } catch (e) {} |
||
60 | try { rimraf.sync(path.join(slug, '.git')) } catch (e) {} |
||
61 | |||
62 | // Write readme.md |
||
63 | fs.writeFileSync(path.join(slug, 'README.md'), '# ' + |
||
64 | util.boxNameDisplay(slug) + '\n\nA Incluable app for ' + util.boxNameDisplay(slug) + '.', 'utf8') |
||
65 | |||
66 | // Git init |
||
67 | var gitSpinner = output.wait('Initializing local Git repository') |
||
68 | child.exec('cd "' + slug + '" && git init', function (err) { |
||
69 | gitSpinner(err ? err : true) |
||
70 | }) |
||
71 | |||
72 | // Download IDE helper |
||
73 | var ideSpinner = output.wait('Downloading code completion helper') |
||
74 | util.downloadHelper(function () { |
||
75 | ideSpinner(true) |
||
76 | }, slug) |
||
77 | }) |
||
78 | } catch (e) { |
||
79 | stopSpinner(e) |
||
80 | } |
||
81 | } |
||
82 |